﻿using AgencyManagerSystem.AsmType;
using AgencyManagerSystem.Common;
using AgencyManagerSystem.Core;
using AgencyManagerSystem.DataFetcher;
using AgencyManagerSystem.Model;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace AgencyManagerSystem.Controllers
{
    public class BillRecordController : ERPControllerBase
    {
        ERPBillRecordFetcher fetcher;
        public BillRecordController() : base()
        {
            this.fetcher = new ERPBillRecordFetcher();
        }
        [HttpGet]
        [RoleFlagAuthorizeAttribute(PolicyDomain.Retail, AppOpt.Exec)]
        public AsmArray<ERPAllBillRecord> ListAll(string jsonCondition, int pos, int size)
        {
            var fetcher2 = new ERPAllBillRecordFetcher();
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RQS|{1}]{0}", jsonCondition, RequestIp));
            int cnt = 0;
            var BillReport = fetcher2.List(Util.ConvertArrayFromJson<Condition>(jsonCondition), pos, size, out cnt);
            var result = new AsmArray<ERPAllBillRecord>() { Data = BillReport, Message = "操作成功", Result = AmsCode.Succ, Cnt = cnt };
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RSP|{1}]{0}", Util.ConvertToJson(result), RequestIp));
            return result;
        }

        [HttpGet]
        [RoleFlagAuthorizeAttribute(PolicyDomain.Retail, AppOpt.Exec)]
        public AsmArray<ERPBillRecord> ListCash(string jsonCondition, int pos, int size)
        {
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RQS|{1}]{0}", jsonCondition, RequestIp));
            int cnt = 0;
            var BillReport = fetcher.List(Util.ConvertArrayFromJson<Condition>(jsonCondition), pos, size, out cnt);
            var BillReport2 = from item in BillReport where item.Type == "收款单" || item.Type == "其他应收" || item.Type == "销售退款"  select item;
            var result = new AsmArray<ERPBillRecord>() { Data = BillReport2, Message = "操作成功", Result = AmsCode.Succ, Cnt = cnt };
            LogHelper.Debug(this.GetType().Name, String.Format("LIST:[RSP|{1}]{0}", Util.ConvertToJson(result), RequestIp));
            return result;
        }
    }
}
